//
//  RecommendSongsTableViewCell.m
//  DayByDay
//
//  Created by dllo on 16/5/13.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "RecommendSongsTableViewCell.h"
#import "RecommendCollectionViewCell.h"

@interface RecommendSongsTableViewCell ()<UICollectionViewDataSource, UICollectionViewDelegate>

@property (nonatomic, strong)UILabel *nameLabel;

@end

@implementation RecommendSongsTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createView];
    }
    
    return self;
}

- (void)createView {
    self.nameLabel = [UILabel new];
    [self.contentView addSubview:self.nameLabel];
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.itemSize = CGSizeMake((WIDTH - 25) / 2, 80);
    layout.minimumInteritemSpacing = 5;
//    layout.minimumLineSpacing
//    self.collectionView
    layout.sectionInset = UIEdgeInsetsMake(0, 10, 0, 10);
    self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 90) collectionViewLayout:layout];
//    self.contentView.backgroundColor = [UIColor greenColor];
    [self.collectionView registerClass:[RecommendCollectionViewCell class] forCellWithReuseIdentifier:NSStringFromClass([RecommendCollectionViewCell class])];
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    [self.contentView addSubview:self.collectionView];
    self.collectionView.backgroundColor = [UIColor clearColor];
    self.backgroundColor = [UIColor clearColor];
}

- (void)setModel:(MusicModel *)model {
    _model = model;
    self.nameLabel.text = _model.name;
    [self.collectionView reloadData];
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    RecommendCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([RecommendCollectionViewCell class]) forIndexPath:indexPath];
    cell.model = self.model.data[indexPath.row];
    return cell;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return self.model.data.count;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    self.nameLabel.frame = CGRectMake(WIDTH / 4, 10, WIDTH / 2, 30);
    self.collectionView.frame = CGRectMake(0, 40, WIDTH, self.contentView.frame.size.height - 40);
    self.nameLabel.textAlignment = 1;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    NSLog(@"%@",indexPath);
    NSLog(@"%ld",collectionView.tag);
    NSLog(@"%@",self.model.data[indexPath.row]);
    self.RecommendBlock(collectionView.tag, self.model.data[indexPath.row]);
    
}



- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
